﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.下单MTO.Service
{

    public class MTO下单Service
    {
        /// <summary>
        /// 根据时间戳取各销售渠道下数量
        /// </summary>
        /// <param name="saleOrderDateStart"></param>
        /// <param name="saleOrderDateEnd"></param>
        /// <returns></returns>
        public static List<SalOrderQueryHeadDTO> getSaleOerQueryDTOList(String saleOrderDateStart, String saleOrderDateEnd)
        {
            return
                FunctionHelper.JsonDeserialization<List<SalOrderQueryHeadDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/MTOOrder/sshirtTag/getSalOrderQueryHeadDTOByTimeStamp?" +
                        "saleOrderDateStart=" + saleOrderDateStart
                        + "&saleOrderDateEnd=" + saleOrderDateEnd)
                    );
        }
        /// <summary>
        /// 销售订单一览
        /// </summary>
        /// <param name="detailIds"></param>
        /// <returns></returns>
        public static List<SaleOrderQueryDTO> getSaleOrderQueryListByDetailIds(List<String> detailIds)
        {
            return
                FunctionHelper.JsonDeserialization<List<SaleOrderQueryDTO>>(
                       RestCall.PostHttp(
                           URL.接口url + "/MTOOrder/sshirtTag/getSaleOrderQueryListByDetailIds",
                           FunctionHelper.JsonSerialization(detailIds)
                           )
                       );
        }
        /// <summary>
        /// 根据销售分录id查找生产工序
        /// </summary>
        /// <param name="saleOrderDetailId"></param>
        /// <returns></returns>
        public static ProjectInstanceSimple getProjectInstanceSimplesBySaleOrderDetailId(String saleOrderDetailId)
        {
            return
                FunctionHelper.JsonDeserialization<ProjectInstanceSimple>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/MTOOrder/sshirtTag/getProjectInstanceSimplesBySaleOrderDetailId?saleOrderDetailId=" + saleOrderDetailId)
                    );
        }

        public static List<OrderCommitDTO返回> getAccomplistOrderBySaleDetailId(String saleOrderDetailId)
        {
            return
                FunctionHelper.JsonDeserialization<List<OrderCommitDTO返回>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/MTOOrder/sshirtTag/getAccomplistOrderBySaleDetailId?detailId=" + saleOrderDetailId)
                    );
        }
        /// <summary>
        /// 根据现货完成销售订单分录
        /// </summary>
        /// <param name="detailIdAndBarCodes"></param>
        public static void mtoWIPDoneByInventory(Dictionary<String, List<String>> detailIdAndBarCodes)
        {
            FunctionHelper.JsonDeserialization<List<SaleOrderQueryDTO>>(
                   RestCall.PostHttp(
                       URL.接口url + "/MTOOrder/sshirtTag/mtoWIPDoneByInventory",
                       FunctionHelper.JsonSerialization(detailIdAndBarCodes)
                       )
                   );
        }
        /// <summary>
        /// 取生产订单对应的一个销售订单
        /// </summary>
        /// <param name="manufactureOrderId"></param>
        public static SaleOrderQueryDTO getOneSaleOrderQueryByManufactureOrderId(String manufactureOrderId)
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<SaleOrderQueryDTO>(
                       RestCall.httpGetMethod(
                           URL.接口url + "/MTOOrder/sshirtTag/getOneSaleOrderQueryByManufactureOrderId?manufactureOrderId=" + manufactureOrderId
                           )
                       );
            }
            catch
            {
                return new SaleOrderQueryDTO();
            }
        }

    }
    public class SaleOrderQueryDTO
    {
        //表头
        public String billNo { get; set; }  //  销售订单号
        public String saleOrderType { get; set; }  //  单位团体、个人
        public DateTime saleOrderDate { get; set; }   //  下单时间

        public String storeId { get; set; } //  门店id
        public String storeName { get; set; }   //  门店名称
        public String assistantId { get; set; } //   业务员id
        public String assistant { get; set; }   //  业务员
        /**
         * 单位团体客户信息
         */
        public String titleConsignee { get; set; }   //  联系人
        public String titleMobile { get; set; }
        public String titleAddressProvince { get; set; }//省
        public String titleAddressCity { get; set; }//市
        public String titleAddressDistrict { get; set; }//区
        public String titleAddressDetail { get; set; }//详细地址
        public String titleZipCode { get; set; }//邮编
        /**
         * 订单主体信息
         */
        public DateTime deliveryDate { get; set; }  //  交期
        public Double payment { get; set; } //  实付价格，可以套号销售日记账中后补
        public String saleType { get; set; }    //  销售方式，微店、淘宝、单位团体
                                                //    private String settleType;  //  结算方式
        public String fetchStyle { get; set; }  //  交货方式,工厂交货(EXW),货交承运人(FCA),船边交货(FAS),默认FCA
        public String payStyle { get; set; }    //  付款方式，默认线上支付；刷卡、现金、赊销




        //继承
        public String id { get; set; }
        public String titleId { get; set; } //  抬头id
        /**
         * 订单状态，生产计划编排——通过库存或者订单解决
         */
        public int status { get; set; }   //  状态 ：未开始生成-0，已开始生成-1，生产完成-2，发运完成-3
        public String saleCompleteType { get; set; }    //  库存、订单
        public String manufactureOrderId { get; set; }  //  生产订单号，对应orderCommitDto
        public String saleBarcode { get; set; } //  产成品水洗
        public Boolean urgent { get; set; } //  是否加急
        public Boolean toBeConfirm { get; set; } //  待确认
        /*
            下单客户填
        */
        /**
         * 订单信息
         */
        public Double orderNumber { get; set; }//订单数量
        public DateTime orderDate { get; set; }//订单时间
        public String remarks { get; set; }//备注
        public String styleSizeCd { get; set; }//尺码

        /*
            选择客户
         */
        /**
         * 客户信息
         */
        public String customerId { get; set; }
        public String customerName { get; set; }    //  客户姓名
        public String consignee { get; set; }   //  收件人
        public String mobile { get; set; }
        public String addressId { get; set; }
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//区
        public String addressDetail { get; set; }//详细地址
        public String zipCode { get; set; }//邮编

        /*
            下单时，根据参考成衣码带进来
         */
        public String refBarcode { get; set; } //  参考成衣条码
        /**
         * 参考款式信息
         */
        private String saleInventoryId { get; set; } //  货号
        /**
         * 销售渠道信息
         */
        public String salesType { get; set; }   //  销售方式    top.toptimus.constValue.SalesTypeConsts
        public String salesChannel { get; set; }   //  销售渠道
        /**
         * 价格信息
         */
        public Double price { get; set; }   //  建议零售价
        /**
         * 款式信息
         */
        public String inventoryNo { get; set; } //  货号
        public String styleId { get; set; }
        public String refStyleId { get; set; }//参考款id
        public String styleCode { get; set; }//款号
        public String styleNameCn { get; set; }//款式名称
        public String styleYear { get; set; }//款式年份
        public String styleSeason { get; set; }//款式季节
        /**
         * 面料信息
         */
        public String styleFabricId { get; set; }//面料id
        public String materialNameCn { get; set; }//面料描述名称
        public String materialCode { get; set; }  //面料号
        public String composition { get; set; }//面料成分
        /**
         * 款式信息
         */
        public String styleCategoryCd { get; set; }

        public SaleOrderQueryDTO()
        {

        }
    }
    public class SaleOrderQueryInfoDTO
    {
        public String billNo { get; set; }  //  销售订单号
        public DateTime saleOrderDate { get; set; }   //  下单时间
        public int status { get; set; }   //  进度 状态 ：已下单-0，已投产-1，生产入库-2，发运完成-3
        public String salesType { get; set; }   //  销售方式    top.toptimus.constValue.SalesTypeConsts
        public String salesChannel { get; set; }   //  销售渠道
        public String customerName { get; set; }    //  客户姓名
        public String mobile { get; set; }
        public String addressInfo { get; set; } //客户地址信息
        public String refBarcode { get; set; } //  产成品水洗
        public String styleInfo { get; set; } //款式信息，面料信息放一起
        public String styleSizeCd { get; set; }//尺码
        public String styleNameCn { get; set; }//尺码
        public Double orderNumber { get; set; }//订单数量
        public Double payment { get; set; } //  实付价格，可以套号销售日记账中后补
        public String saleOrderType { get; set; }  //  单位团体、个人
        public Double price { get; set; }   //  建议零售价
        public String storeName { get; set; }   //  门店名称
        public String assistant { get; set; }   //  业务员
        public String remarks { get; set; }//备注
        public String manufactureOrderId { get; set; }  //  生产订单号，对应orderCommitDto
        public String urgent { get; set; } //  是否加急
        public String toBeConfirm { get; set; } //  待确认
        public String id { get; set; }
        public String materialNameCn { get; set; }//面料描述名称
        public String materialCode { get; set; }  //面料号
        public String composition { get; set; }//面料成分

        public String orderInfo { get; set; }




        public SaleOrderQueryInfoDTO(SaleOrderQueryDTO saleOrderQueryDTO)
        {
            this.billNo = saleOrderQueryDTO.billNo;
            this.saleOrderDate = saleOrderQueryDTO.saleOrderDate;
            this.status = (saleOrderQueryDTO.status + 1) * 25;
            this.salesType = saleOrderQueryDTO.salesType;
            this.salesChannel = saleOrderQueryDTO.salesChannel;
            this.customerName = saleOrderQueryDTO.customerName;
            this.mobile = saleOrderQueryDTO.mobile;
            this.addressInfo = "客户地址：" +
                saleOrderQueryDTO.addressProvince
                + saleOrderQueryDTO.addressCity
                + saleOrderQueryDTO.addressDistrict
                + saleOrderQueryDTO.addressDetail
                + saleOrderQueryDTO.zipCode;
            this.refBarcode = saleOrderQueryDTO.refBarcode;
            this.styleInfo =
                //saleOrderQueryDTO.styleNameCn + "\n"
                "尺码：" + saleOrderQueryDTO.styleSizeCd + "\n" +
                "面料号：" + saleOrderQueryDTO.materialCode + "\n" +
                "下单数量：" + saleOrderQueryDTO.orderNumber + "\n" +
                "面料名称：" + saleOrderQueryDTO.materialNameCn + "\n";
            this.styleSizeCd = saleOrderQueryDTO.styleSizeCd;
            this.styleNameCn = saleOrderQueryDTO.styleNameCn;
            this.orderNumber = saleOrderQueryDTO.orderNumber;
            this.payment = saleOrderQueryDTO.payment;
            this.saleOrderType = saleOrderQueryDTO.saleOrderType;
            this.price = saleOrderQueryDTO.price;
            this.orderInfo =
                "成份：" + saleOrderQueryDTO.composition + "\n" +
                "下单门店：" + saleOrderQueryDTO.storeName + "\n" +
                "业务员：" + saleOrderQueryDTO.assistant + "\n" +
                "订单备注：" + saleOrderQueryDTO.remarks + "\n" +
                "建议零售价：" + saleOrderQueryDTO.price + "\n" +
                "实付价格：" + saleOrderQueryDTO.payment + "\n";
            this.id = saleOrderQueryDTO.id;
            this.urgent = saleOrderQueryDTO.urgent.ToString();
            this.toBeConfirm = saleOrderQueryDTO.toBeConfirm.ToString();

            this.materialCode = saleOrderQueryDTO.materialCode;
            this.materialNameCn = saleOrderQueryDTO.materialNameCn;
            this.composition = saleOrderQueryDTO.composition;
        }
    }
    public class SalOrderQueryHeadDTO
    {
        public String salesType { get; set; }   //  销售方式    top.toptimus.constValue.SalesTypeConsts
        public String salesChannel { get; set; }    //  销售渠道
        public Double quantity { get; set; }   //  数量
        public List<String> detailIds { get; set; } = new List<String>(); //  分录id一览
        public SalOrderQueryHeadDTO()
        {

        }
    }
    public class OrderShippedDTO
    {
        public String urgentFlg { get; set; }//是否加急
        public Double batchQuantity { get; set; }//数量
        public int orderId { get; set; }//订单id
        public String orderNo { get; set; }//订单号
        public DateTime orderDate { get; set; }//订单日期
        public String styleNameCn { get; set; }//款式名称
        public String styleSizeCd { get; set; }//款式尺寸
        public String materialCode { get; set; }//面料号
        public String materialNameCn { get; set; }//面料名称
        public String customerName { get; set; }//客户名称
        public String consignee { get; set; }//收件人
        public String mobile { get; set; }//手机
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//县区
        public String addressDetail { get; set; }//详细地址
        public String sfExpressNo { get; set; }//快递单号
        public String shopId { get; set; }//店铺id
        public String shopName { get; set; }//店铺名称
        public OrderShippedDTO()
        {

        }
    }
    public class ProjectInstanceSimpleDTO
    {
        public String id { get; set; }
        public String orderId { get; set; } //  订单id
        public String batchNo { get; set; } //  生产批次
        //  WBS模板信息
        public String wbsTemplateId { get; set; }   //  WBS模板id
        public String wbsItemId { get; set; }  //  WBS项目id
        public String parentId { get; set; }    //  父id
        public String activityDescription { get; set; } //  工作描述
        public String code { get; set; }  //  WBS编码顺序
        public int index { get; set; }   //  顺序
        //  WBS实例信息
        public DateTime actualFinishDate { get; set; }  //  实际完成时间
        public DateTime startTimePlanned { get; set; }  //  计划开始时间（工单时间）
        public double duration { get; set; }    //  工期
        public double costPlusFixedFee { get; set; }   //  成本加固定费用
        public String responsorId { get; set; }  //  任务负责人ID
        public String responsor { get; set; }    //  任务负责人
        public ProjectInstanceSimpleDTO()
        {

        }
    }
    public class ProjectInstanceSimple
    {
        public List<OrderShippedDTO> orderShippedDTO { get; set; } = new List<OrderShippedDTO>();
        public List<ProjectInstanceSimpleDTO> projectInstanceSimpleDTOs { get; set; } = new List<ProjectInstanceSimpleDTO>();
        public ProjectInstanceSimple()
        {

        }

        public ProjectInstanceSimple(List<OrderShippedDTO> orderShippedDTO, List<ProjectInstanceSimpleDTO> projectInstanceSimpleDTOs)
        {
            this.orderShippedDTO = orderShippedDTO;
            this.projectInstanceSimpleDTOs = projectInstanceSimpleDTOs;
        }
    }

}
